import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:fnos_tv_desktop/core/api/api_auth.dart';

import '../api_exception.dart';

class NoLoginInterceptor extends Interceptor {
  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    options.headers['Authx'] = generateSignature(options);
    super.onRequest(options, handler);
  }

  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) {
    final json = response.data;
    final code = json['code'] as int;
    if (code == 0) {
      response.data = json['data'];
      super.onResponse(response, handler);
    } else {
      throw ApiException(code, json['msg']);
    }
  }
}
